# -*- coding:utf-8 -*-

from PyQt4.QtCore import QObject, SIGNAL
from downloadthread import *

class Downloader(QObject):
    def __init__(self):
        QObject.__init__(self)
        self.thread = DownloadThread()

        self.connect(self.thread,SIGNAL("started()"),self.started)
        self.connect(self.thread,SIGNAL("done(bool)"),self.done)
        self.connect(self.thread,SIGNAL("updateProgress(int,int)"),self.updateProgress)
        self.connect(self.thread,SIGNAL("gotError(const QString&)"),self.gotError)

    def download(self,date):
        self.thread.setDate(date)
        self.thread.start()

    def getImageData(self):
        return self.thread.imageData

    def started(self):
        self.emit(SIGNAL("started()"))

    def updateProgress(self, downloaded, total):
        self.emit(SIGNAL("updateProgress(int,int)"), downloaded, total)

    def done(self,error):
        self.emit(SIGNAL("done(bool)"), error)

    def gotError(self,errorMessage):
        self.emit(SIGNAL("gotError(const QString&)"), errorMessage)
